//
//  ViewController.m
//  CAAnimationGroup
//
//  Created by Xwoder on 17/1/29.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "ViewController.h"
#import "UIView+ALQuickFrame.h"

@interface ViewController ()

@property (nonatomic, strong) UIView *orangeView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *orangeView = [[UIView alloc] init];
    orangeView.backgroundColor = [UIColor orangeColor];
    orangeView.size = CGSizeMake(320, 320);
    orangeView.center = self.view.center;
    [self.view addSubview:orangeView];
    self.orangeView = orangeView;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    // 旋转
    CABasicAnimation *rotationAnimation = [CABasicAnimation animation];
    rotationAnimation.keyPath = @"transform.rotation";
    rotationAnimation.toValue = @(M_PI);
    
    // 缩放
    CABasicAnimation *scaleAnimation = [CABasicAnimation animation];
    scaleAnimation.keyPath = @"transform.scale";
    scaleAnimation.toValue = @(0.1);
    
    // 变色
    CABasicAnimation *colorAnimation = [CABasicAnimation animation];
    colorAnimation.keyPath = @"backgroundColor";
    colorAnimation.toValue = (id)[UIColor blueColor].CGColor;
    
    // 动画组
    CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
    group.animations = @[rotationAnimation, scaleAnimation, colorAnimation];
    group.duration = 1;
    group.autoreverses = YES;
    
    // 将动画组添加至图层
    [self.orangeView.layer addAnimation:group forKey:nil];
}

@end
